package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeetingUserSignature;
import com.ruoyi.system.service.IMeetingUserSignatureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议签到Controller
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/system/signature")
public class MeetingUserSignatureController extends BaseController
{
    @Autowired
    private IMeetingUserSignatureService meetingUserSignatureService;

    /**
     * 查询会议签到列表
     */
    @PreAuthorize("@ss.hasPermi('system:signature:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MeetingUserSignature meetingUserSignature)
    {
        setStartPage(meetingUserSignature.getPageNum(),meetingUserSignature.getPageSize());
        List<MeetingUserSignature> list = meetingUserSignatureService.selectMeetingUserSignatureList(meetingUserSignature);
        return getDataTable(list);
    }


    /**
     * 获取会议签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:signature:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingUserSignatureService.selectMeetingUserSignatureById(id));
    }

    /**
     * 新增会议签到
     */
    @PreAuthorize("@ss.hasPermi('system:signature:add')")
    @Log(title = "会议签到", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MeetingUserSignature meetingUserSignature)
    {
        try {
            List<MeetingUserSignature> meetingUserSignatureList = meetingUserSignature.getMeetingUserSignatureList();
            for(MeetingUserSignature userSignature : meetingUserSignatureList){
                userSignature.setCreateBy(String.valueOf(getUserId()));
                meetingUserSignatureService.insertMeetingUserSignature(userSignature);
            }
            return AjaxResult.success("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.success("添加失败");
        }
    }

    /**
     * 签到
     */
    @PreAuthorize("@ss.hasPermi('system:signature:edit')")
    @Log(title = "会议签到", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MeetingUserSignature meetingUserSignature)
    {
        return meetingUserSignatureService.updateMeetingUserSignature(meetingUserSignature);
    }

//    /**
//     * 删除会议签到
//     */
//    @PreAuthorize("@ss.hasPermi('system:signature:remove')")
//    @Log(title = "会议签到", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{id}")
//    public AjaxResult remove(@PathVariable Long id)
//    {
//        return toAjax(meetingUserSignatureService.deleteMeetingUserSignatureById(id));
//    }
}
